package cn.com.tianpeidong.restaurantadmin.project.admin.desk.rest;

import cn.com.tianpeidong.restaurantadmin.project.admin.desk.entity.DeskInfo;
import cn.com.tianpeidong.restaurantadmin.project.admin.desk.service.IDeskService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author tianpeidong
 * @version 创建时间: 19-6-8 下午7:20
 */
@RestController
@RequestMapping("/desk")
public class DeskController {

    @Autowired
    private IDeskService deskService;

    @GetMapping("/list")
    @RequiresPermissions("desk:list")
    public ResponseEntity showDeskList() {
        return ResponseEntity.ok(deskService.list());
    }

    @GetMapping
    @RequiresPermissions("desk:list")
    public ResponseEntity showDeskInfo(@RequestParam("id") Long id) {
        return ResponseEntity.ok(deskService.getById(id));
    }

    @PostMapping
    @RequiresPermissions("desk:add")
    public ResponseEntity addDesk(@RequestBody DeskInfo deskInfo) {
        return ResponseEntity.ok(deskService.newDesk(deskInfo));
    }

    @PatchMapping
    @RequiresPermissions("desk:delete")
    public ResponseEntity deleteDesk(@RequestBody DeskInfo deskInfo) {
        return ResponseEntity.ok(deskService.deleteDesk(deskInfo));
    }

    @PutMapping
    @RequiresPermissions("desk:edit")
    public ResponseEntity updateDesk(@RequestBody DeskInfo deskInfo) {
        return ResponseEntity.ok(deskService.updateDeskStatus(deskInfo));
    }

}
